﻿using Application.MainModule.SoundexCodesManagement;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using Domain.MainModule.SoundexCodes;
using Domain.MainModule.Entities;
using System.Collections.Generic;

using Infraestructure.CrossCutting.IoC;

namespace Application.MainModule.Tests
{
    /// <summary>
    ///This is a test class for SoundexCodeManagementServiceTest and is intended
    ///to contain all SoundexCodeManagementServiceTest Unit Tests
    ///</summary>
    [TestClass()]
    public class SoundexCodeManagementServiceTest
    {
        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion

        /// <summary>
        ///A test for AddSoundexCode null soundex code throw argument null exception.
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void AddSoundexCode_NullSoundexCodeThrowArgumentNullException_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();

            //Act
            target.AddSoundexCode(null);
        }

        /// <summary>
        ///A test for AddSoundexCode
        ///</summary>
        [TestMethod()]
        public void AddSoundexCode_Invoke_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();
            Guid soundexCodeId = Guid.Parse("ABCDF456-CCCC-AAAA-5678-AAAACCBBBBBB");
            SoundexCode soundexCode = new SoundexCode()
            {
                SoundexCodeId = soundexCodeId,
                Value = "Test Soundex Code"
            };
            List<SoundexCode> result = null;

            //Act
            target.AddSoundexCode(soundexCode);

            //Assert
            result = target.FindSoundexCodeByValue("Test Soundex Code");
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual(soundexCodeId, result[0].SoundexCodeId);
            target.RemoveSoundexCode(result[0]);
        }

        /// <summary>
        ///A test for ChangeSoundexCode null soundex code throw argument null exception.
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void ChangeSoundexCode_NullSoundexCodeThrowArgumentNullException_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();

            //Act
            target.ChangeSoundexCode(null);
        }
        
        /// <summary>
        ///A test for ChangeSoundexCode
        ///</summary>
        [TestMethod()]
        public void ChangeSoundexCode_Invoke_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();
            string value = "Code 01";
            List<SoundexCode> soundexCodes = null;
            List<SoundexCode> result = null;

            //Act
            soundexCodes = target.FindSoundexCodeByValue(value);
            soundexCodes[0].Code = "Code modified";
            target.ChangeSoundexCode(soundexCodes[0]);

            //Assert
            result = target.FindSoundexCodeByValue(value);
            Assert.IsNotNull(result);
            Assert.AreEqual(1, result.Count);
            Assert.AreEqual("Code modified", result[0].Code);
        }

        /// <summary>
        ///A test for FindSoundexCodeByUserId
        ///</summary>
        [TestMethod()]
        public void FindSoundexCodeByUserId_Invoke_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();
            Guid userId = Guid.Parse("ABCDF456-CCCC-AAAA-BBBB-AAAACCBBBBBB");
            List<SoundexCode> soundexCodes = null;

            //Act
            soundexCodes = target.FindSoundexCodeByUserId(userId);

            //Assert
            Assert.IsNotNull(soundexCodes);
            Assert.AreEqual(1, soundexCodes.Count);
            Assert.AreEqual(userId, soundexCodes[0].UserId);
        }

        /// <summary>
        ///A test for FindSoundexCodeByValue null soundex code throw argument null exception.
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void FindSoundexCodeByValue_NullSoundexCodeThrowArgumentNullException_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();

            //Act
            target.FindSoundexCodeByValue(null);
        }

        /// <summary>
        ///A test for FindSoundexCodeByValue
        ///</summary>
        [TestMethod()]
        public void FindSoundexCodeByValue_Invoke_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();
            string value = "Soundex Code 02";
            List<SoundexCode> soundexCodes = null;

            //Act
            soundexCodes = target.FindSoundexCodeByValue(value);

            //Assert
            Assert.IsNotNull(soundexCodes);
            Assert.AreEqual(1, soundexCodes.Count);
            Assert.AreEqual(value, soundexCodes[0].Value);
        }

        /// <summary>
        ///A test for RemoveSoundexCode null soundex code throw argument null exception.
        ///</summary>
        [TestMethod()]
        [ExpectedException(typeof(ArgumentNullException))]
        public void RemoveSoundexCode_NullSoundexCodeThrowArgumentNullException_Test()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();

            //Act
            target.RemoveSoundexCode(null);
        }

        /// <summary>
        ///A test for RemoveSoundexCode
        ///</summary>
        [TestMethod()]
        public void RemoveSoundexCodeTest()
        {
            //Arrange
            ISoundexCodeManagementService target = IoCFactory.Instance.CurrentContainer.Resolve<ISoundexCodeManagementService>();
            Guid soundexCodeId = Guid.Parse("ABCDF456-CCCC-AAAA-5678-AAAACCBBBBBB");
            SoundexCode soundexCode = new SoundexCode()
            {
                SoundexCodeId = soundexCodeId,
                Value = "Test Soundex Code"
            };
            
            //Act
            target.AddSoundexCode(soundexCode);
            target.RemoveSoundexCode(soundexCode);
        }
    }
}
